const admin = require("../server/admin")
const { getSetting, updataSetting } = require("../config/getAndUpdataSetting")
// 新建robot对话
module.exports = function (app) {
    app.post("/admin/isadmin", (req, res) => {
        admin.isAdmin(req, res)
    })
    app.post("/admin/registadmin", (req, res) => {
        admin.register(req, res)
    })
    app.post("/admin/addadmin", (req, res) => {
        admin.addAdmin(req, res)
    })
    app.post("/admin/getadminlist", (req, res) => {
        admin.getAdminList(req, res)
    })

    app.post("/admin/deleteadmin", (req, res) => {
        admin.deleteAdmin(req, res)
    })

    app.post("/admin/getadmininfo", (req, res) => {
        admin.getAdminInfo(req, res)
    })
    app.post("/admin/getchartdate", (req, res) => {
        admin.getChartDate(req, res)
    })
    //用户数据展示和修改
    app.post("/admin/getpageusers", (req, res) => {
        admin.getPageUsers(req, res)
    })

    //用户数据展示和修改
    app.post("/admin/deleteuser", (req, res) => {
        admin.deleteUser(req, res)
    })
    //用户数据展示和修改
    app.post("/admin/updateuserdetail", (req, res) => {
        admin.updateUserDetail(req, res)
    })
    app.post("/admin/getsetting", (req, res) => {
        let { body } = req
        console.log(body, "body");
        let setting = getSetting()
        console.log(setting.emailSmtp, "setting");
        switch (body.type) {
            case "email":
                res.send({ status: 200, data: setting.emailSmtp })
                break;
            case "map":
                res.send({ status: 200, data: setting.map })
                break;
            case "spark":
                res.send({ status: 200, data: setting.spark })
                break;
            default:
                res.send({ status: 400, msg: "请求错误" })
        }
    })
    app.post("/admin/updatesetting", (req, res) => {
        let { body } = req
        console.log(body, "body");
        let setting = getSetting()  
        switch (body.type) {
            case "email":
                updataSetting(body.data,"emailSmtp",res)
                break;
            case "map":
                updataSetting(body.data,"map",res)
                break;
            case "spark":
                updataSetting(body.data,"spark",res)
                break;
            default:
                res.send({ status: 400, msg: "请求错误" })
        }
    })

}